var viewer = new Cesium.Viewer("cesiumViewer", {
    animation: false,
    fullscreenButton: false,
    timeline: false,
    projectionPicker: true,
    baseLayerPicker: false,
    requestRenderMode: true,


    // terrainProvider : new Cesium.CesiumTerrainProvider({
    //     url : URL_CONFIG.SiChuan_TERRAIN,
    //     isSct : true//地形服务源自SuperMap iServer发布时需设置isSct为true
    // }),
    // terrainProvider : new Cesium.CesiumTerrainProvider({
    //     url : 'http://map.tianxiao2.com/geoserver/Tianxiao2/wms',
    //     requestVertexNormals : true
    // })
});

viewer.scene.debugShowFramesPerSecond = true;
// 

var imageryLayers = viewer.imageryLayers;
// var provider_mec = new Cesium.SuperMapImageryProvider({
//     url : 'http://www.supermapol.com/realspace/services/map-China400/rest/maps/China400'
// });

// var provider_mec = new Cesium.ArcGisMapServerImageryProvider({
//     url: 'https://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/',
//     enablePickFeatures: false
// });

// var imagery_mec;
//初始化时添加经纬度投影地图图层
// imagery_mec = imageryLayers.addImageryProvider(provider_mec);
// imagery_mec.alpha = 1.0;

var scene = viewer.scene;

// var terrainProvider = new Cesium.GeoserverTerrainProvider({
//     url: "http://localhost:8080/geoserver/elevation/wms",
//     layerName: "SRTM90",
//     styleName: "grayToColor",
//     waterMask: true
// });

// scene.globe.terrainProvider = terrainProvider;

// var providerTwo = new Cesium.WebMapServiceImageryProvider({
//     url: 'http://map.tianxiao2.com/geoserver/Tianxiao2/wms',
//     layers: 'Tianxiao2:hgdsm',
//     parameters: {
//         service: 'WMS',
//         format: 'image/png',
//         transparent: true,
//     }
// });

//var image = viewer.imageryLayers.addImageryProvider(providerTwo);
//viewer.flyTo(image);

var layer = new Cesium.WebMapTileServiceImageryProvider({
    url: 'http://t0.tianditu.gov.cn/img_w/wmts?tk=012dd667135a865ed0b1f9b1b8b0da15',
    layer: 'img',
    style: 'default',
    tileMatrixSetID: 'w',
    format: 'tiles',
    maximumLevel: 18
});

viewer.imageryLayers.addImageryProvider(layer);

//加载影像注记

var layer1 = new Cesium.WebMapTileServiceImageryProvider({
    url: 'http://t0.tianditu.gov.cn/cia_w/wmts?tk=012dd667135a865ed0b1f9b1b8b0da15',
    layer: 'cia',
    style: 'default',
    tileMatrixSetID: 'w',
    format: 'tiles',
    maximumLevel: 18
});

viewer.imageryLayers.addImageryProvider(layer1);



var handle = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handle.setInputAction(function (evt) {
        var picres = viewer.scene.pickPosition(evt.position, new Cesium.Cartesian3());
        var ellipsoid = viewer.scene.globe.ellipsoid;
        var cartographic = ellipsoid.cartesianToCartographic(picres);
        var lat = Cesium.Math.toDegrees(cartographic.latitude);
        var lng = Cesium.Math.toDegrees(cartographic.longitude);
        var msg1 = '经度：' + cartographic.longitude + ', 纬度：' + cartographic.longitude;
        var msg = '经度：' + lng + ', 纬度：' + lat;
        //alert(msg);
        console.log(msg1);
        console.log(msg);
    },
    Cesium.ScreenSpaceEventType.LEFT_CLICK);


viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(114.39364451351774, 30.508365960463802, 500.0),
    orientation: {
        heading: Cesium.Math.toRadians(175.0),
        pitch: Cesium.Math.toRadians(-45.0),
        roll: 0.0
    }
});


// viewer.scene.postRender.addEventListener(function(){

//     var c = viewer.scene.camera;
//     var msg = "heading: " + c.heading +  ", pitch: " + c.pitch +  ", roll: " + c.roll;

//     console.log(msg);
// });

function testFlyTo() {
    viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(108.536, 35.079, 1500.0)
    });
}
//scene.imagerySplitPosition = 0.5;